const express=require('express')
const pool=require('../pool')
const router=express.Router()
module.exports=router
// 新闻列表
router.get('/list',(req,res,next)=>{
	let {pno,pagenum,fid} = req.query
	pagenum=pagenum ? Number(pagenum) : 10
	const start=(pno-1)*pagenum
	pool.query('SELECT nid,title,news_time,img FROM news WHERE family_id=? LIMIT ?,?',[fid,start,pagenum],(err,result)=>{
		if(err){
			next(err)
			return
		}
		pool.query('SELECT count(*) count FROM news',(err,count)=>{
			if(err){
				next(err)
				return
			}
			res.send({code:200,msg:'操作成功',fid,data:result,pno:pno*1,Pagecount:Math.ceil(count[0].count/pagenum)})
		})
	})
})
// 新闻详情
router.get('/newsDetails',(req,res,next)=>{
	pool.query('SELECT * FROM news WHERE nid=?',[req.query.nid],(err,result)=>{
		if(err){
			next(err)
			return
		}
		res.send({statusCode:'OK',code:200,result:result[0]})
	})
})